// console.log('geturlstate_post.js running')

// 假设你有一个包含链接的数组  
const data = {
    "nuker": { href: 'https://nuker.zsuuu.com/', name: "Shard核弹监视" },
    "pan": { href: 'https://pan.zsuuu.com/', name: "可道云" },
    "pq": { href: 'https://pq.zsuuu.com/', name: "无尽任务" },
    "nstar": { href: 'https://nstar.zsuuu.com/', name: "新星帝国" },
    "riji": { href: 'https://riji.zsuuu.com/', name: "日记本" },
    "xiangce": { href: 'https://xc.zsuuu.com/', name: "白色相簿" },
    "pengyouquan": { href: 'https://pyq.zsuuu.com/', name: "朋友圈" },
    "tiyu": { href: 'https://tyjsq.zsuuu.com/', name: "体育计算器" },
    "mffapi": { href: 'http://api-screeps.mofengfeng.com/api/portals/find_route?from=shard0_W1N1&to=shard3_W2N2', name: "Mofeng星门寻路" },
    "api": { href: 'https://api.zsuuu.com', name: "自制接口" },
    "mffapihttps": { href: 'https://api.zsuuu.com', name: "Mofeng星门寻路(https转发)" },
    "screepsdownload": { href: 'https://www.zsuuu.com/download.html', name: "安卓版Screeps下载" },
    "yishu": { href: 'https://note.zsuuu.com/', name: "遗书" },
    "control": { href: 'https://www.zsuuu.com/', name: "控制面板" },
    "screepsapi": { href: 'https://screeps-cn.github.io', name: "Screeps文档api" },
};

// 假设你的Flask应用端点是'/api/data'  
const url = 'https://api.zsuuu.com/checkurl_post';

// 使用fetch发送POST请求  
fetch(url, {
    method: 'POST', // 或者 'put'  
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(data), // 将JavaScript对象转换为JSON字符串  
})
    .then(response => {
        if (!response.ok) {
            throw new Error('Failed to fetch data');
        }
        return response.json(); // 解析响应的JSON数据  
    })
    .then(data => {
        // console.log(data); // 处理返回的数据 
        const keys = Object.keys(data);  
        for (const key of keys) {  
            const value = data[key];  
            // 处理每个属性的值  
            console.log(key, value); // 或者其他处理逻辑  
            if (value.state_code == 200){
                document.getElementById(key).style.backgroundColor = "green"
            }
        }
    })
    .catch(error => {
        console.log('Error:', error);
    });